//
//  PlatformViewController.m
//  OrderSeat
//
//  Created by haiming on 13-10-17.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "PlatformViewController.h"
#import "UIImageView+WebCache.h"

@implementation PlatformViewController

- (id)init
{
    self = [super initWithNibClass:[PlatformViewController class]];
    if (self) {
        _dataSource = [[PlatformDataSource alloc] initWithVC:self];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self createLeftButton];
    [self setNavigationTitle:@"微信公众账号"];
    [_dataSource fetchWeixinCode];
}

#pragma 隐藏tabbar
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [[AppDelegate sharedInstance] hideTabBar:self.tabBarController];
}

- (void)leftButtonClick:(id)sender
{
    [[AppDelegate sharedInstance] showTabBar:self.tabBarController];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)setImageCode:(NSString *)url
{
    [self.codeImage setImageWithURL:[NSURL URLWithString:url]];
}

@end

//==============================================================================
#pragma=========数据源实现========================================================
//==============================================================================

@implementation PlatformDataSource

- (id)initWithVC:(id)viewController
{
    self = [super init];
    if (self) {
        self.viewController = viewController;
    }
    return self;
}

- (void)fetchWeixinCode
{
    [self get:API_WEIXIN];
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    CLog(@"%@", request.responseString);
    
    NSDictionary *json = [request.responseData JSONValue];
    if ([[json objectForKey:@"error_code"] intValue] != 0) {
        return;
    }
    
    NSString *url = [json objectForKey:@"erweima"];
    [_viewController setImageCode:url];
}

@end


